
import gen_base_table as a
import gen_base_bai_da_table as b
import gen_zi_table as c
import gen_zi_with_shun_table as d
import gen_zi_bai_da_table as e
import gen_zi_bai_da_with_shun_table as f

def Init_head(file, file_name, table_name):
  file.writelines("#ifndef " + file_name.upper() + "_H \n")
  file.writelines("#define " + file_name.upper() + "_H \n")
  file.writelines("#include <map> \n")
  file.writelines("#include <string> \n")
  file.writelines("#ifdef GAME_SERVER_DLL \n")
  file.writelines("#include <server2.0/ServerShared/Common.h> \n")
  file.writelines("#else \n")
  file.writelines("#include <GameCore/Common.h> \n")
  file.writelines("#endif \n")
  file.writelines("#include <global/CardDef.h> \n")
  file.writelines("#define CARD_COUNT 34 \n")
  file.writelines("#define CARD_COUNT_NO_ZI	27 \n")
  file.writelines("typedef std::vector < MJCARD > CardVector; \n")
  file.writelines("typedef std::vector < MJCARD > CardVector; \n\n")

  file.writelines("class " + file_name.title() + " \n")
  file.writelines("{ \n")
  file.writelines("public: \n")
  file.writelines(file_name.title() + "(); \n")
  file.writelines("~" + file_name.title() + "(){} \n")
  file.writelines("public: \n")
  file.writelines("void Init(); \n")
  file.writelines("public: \n")
  file.writelines("std::map < uint32_t, uint32_t > " + table_name + "; \n")
  file.writelines("}; \n")
  file.writelines("# endif \n")

def Init_Cpp_head(file, file_name,table_name):
  file.writelines('#include "' + file_name.title() + '.h" \n\n')
  file.writelines(file_name.title() + "::" + file_name.title() + "() \n")
  file.writelines("{ \n")
  file.writelines(table_name + ".clear(); \n")
  file.writelines("} \n")
  file.writelines("void " + file_name.title() +"::Init() \n")
  file.writelines("{ \n")


a.get_base_table()
a.gen_eye_base_table()

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\base_table.h", "w") as file:
#   Init_head(file,"base_table","baseTable")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\\base_table.txt","w") as file:
    # Init_Cpp_head(file, "base_table", "baseTable")
    for s in a.base_table:
        # ss = "baseTable.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key=s, value=a.base_table[s])
        ss = "{key},{value}".format(key = s,value= a.base_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\eye_base_table.h", "w") as file:
#   Init_head(file,"eye_base_table","eyeBaseTable")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\eye_base_table.txt","w") as file:
    # Init_Cpp_head(file, "eye_base_table", "eyeBaseTable")
    for s in a.eye_base_table:
        # ss = "eyeBaseTable.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key = s,value=a.eye_base_table[s])
        ss = "{key},{value}".format(key = s,value= a.eye_base_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")


b.gen_table()
b.gen_eye_table()

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_base_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_base_table" + str(i), "baiDaBaseTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_base_table" + str(i) + ".txt","w") as file:
        # Init_Cpp_head(file, "baida_base_table" + str(i), "baiDaBaseTable[" + str(i) + "]")
        for s in b.table[i]:
            # ss = "baiDaBaseTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value = b.table[i][s])
            ss = "{key},{value}".format(key = s,value = b.table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_base_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_eye_base_table" + str(i), "baidaEyeBaseTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_base_table" + str(i) +".txt","w") as file:
        # Init_Cpp_head(file, "baida_eye_base_table" + str(i), "baidaEyeBaseTable[" + str(i) + "]")
        for s in b.eye_table[i]:
            # ss = "baidaEyeBaseTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value = b.eye_table[i][s])
            ss = "{key},{value}".format(key=s,value = b.eye_table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")

c.get_base_table()
c.gen_eye_base_table()

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\zi_table.h", "w") as file:
#   Init_head(file,"zi_table","zi_table")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\\zi_table.txt","w") as file:
    # Init_Cpp_head(file, "zi_table", "zi_table")
    for s in c.zi_table:
        # ss = "zi_table.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key = s,value=c.zi_table[s])
        ss = "{key},{value}".format(key=s,value=c.zi_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\eye_zi_table.h", "w") as file:
#   Init_head(file,"eye_zi_table","eye_zi_table")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\eye_zi_table.txt","w") as file:
    # Init_Cpp_head(file, "eye_zi_table", "eye_zi_table")
    for s in c.eye_zi_table:
        # ss = "eye_zi_table.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key = s,value=c.eye_zi_table[s])
        ss = "{key},{value}".format(key=s,value=c.eye_zi_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")


zi_combo_list = d.get_base_table()
zi_eye_combo_list,value_list = d.gen_eye_base_table()
for combo_list in zi_combo_list:
    d.add_table(combo_list)

for index,data in enumerate(zi_eye_combo_list):
    d.add_table(data,value_list[index])

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\zi_with_shun_table.h", "w") as file:
#   Init_head(file,"zi_with_shun_table","zi_with_shun_table")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\\zi_with_shun_table.txt","w") as file:
    # Init_Cpp_head(file, "zi_with_shun_table", "zi_with_shun_table")
    for s in d.zi_with_shun_table:
        # ss = "zi_with_shun_table.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key = s,value=d.zi_with_shun_table[s])
        ss = "{key},{value}".format(key=s,value=d.zi_with_shun_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")

# with open("E:\PythonWorkSpace\generate_list_hu\\tables\\eye_zi_with_shun_table.h", "w") as file:
#   Init_head(file,"eye_zi_with_shun_table","eye_zi_with_shun_table")

with open("E:\PythonWorkSpace\generate_list_hu\\tables\eye_zi_with_shun_table.txt","w") as file:
    # Init_Cpp_head(file, "eye_zi_with_shun_table", "eye_zi_with_shun_table")
    for s in d.eye_zi_with_shun_table:
        # ss = "eye_zi_with_shun_table.insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(key = s,value=d.eye_zi_with_shun_table[s])
        ss = "{key},{value}".format(key=s,value=d.eye_zi_with_shun_table[s])
        file.writelines(ss + "\n")
    # file.writelines("} \n")


e.gen_table()
e.gen_eye_table()

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_zi_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_zi_table" + str(i), "baiDaZiTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_zi_table" + str(i) + ".txt","w") as file:
        # Init_Cpp_head(file, "baida_zi_table" + str(i), "baiDaZiTable[" + str(i) + "]")
        for s in e.zi_table[i]:
            # ss = "baiDaZiTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value=e.zi_table[i][s])
            ss = "{key},{value}".format(key = s,value=e.zi_table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_zi_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_eye_zi_table" + str(i), "baidaEyeZiTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_zi_table" + str(i) +".txt","w") as file:
        # Init_Cpp_head(file, "baida_eye_zi_table" + str(i), "baidaEyeZiTable[" + str(i) + "]")
        for s in e.eye_zi_table[i]:
            # ss = "baidaEyeZiTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value=e.eye_zi_table[i][s])
            ss = "{key},{value}".format(key=s,value=e.eye_zi_table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")

f.gen_zi_bai_da_with_shun_table()
f.gen_eye_zi_bai_da_with_shun_table()

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_zi_with_shun_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_zi_with_shun_table" + str(i), "baiDaZiWithShunTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_zi_with_shun_table" + str(i) + ".txt","w") as file:
        # Init_Cpp_head(file, "baida_zi_with_shun_table" + str(i), "baiDaZiWithShunTable[" + str(i) + "]")
        for s in f.zi_bai_da_with_shun_table[i]:
            # ss = "baiDaZiWithShunTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value=f.zi_bai_da_with_shun_table[i][s])
            ss = "{key},{value}".format(key = s,value=f.zi_bai_da_with_shun_table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")

for i in range(0,5):
    # with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_zi_with_shun_table" + str(i) + ".h", "w") as file:
    #     Init_head(file, "baida_eye_zi_with_shun_table" + str(i), "baidaEyeZiWithShunTable[" + str(i) + "]")

    with open("E:\PythonWorkSpace\generate_list_hu\\tables\\baida_eye_zi_with_shun_table" + str(i) +".txt","w") as file:
        # Init_Cpp_head(file,  "baida_eye_zi_with_shun_table" + str(i), "baidaEyeZiWithShunTable[" + str(i) + "]")
        for s in f.eye_zi_bai_da_with_shun_table[i]:
            # ss = "baidaEyeZiWithShunTable[{index}].insert(std::pair<uint32_t,uint32_t>({key},{value}));".format(index = i,key = s,value=f.eye_zi_bai_da_with_shun_table[i][s])
            ss = "{key},{value}".format(key=s,value=f.eye_zi_bai_da_with_shun_table[i][s])
            file.writelines(ss + "\n")
        # file.writelines("} \n")



